launchApp("今日头条极速版");
sleep(2000)
if (id("ko").className("android.widget.TextView").textStartsWith("0").findOne(4000)) {
    id("ko").className("android.widget.TextView").textStartsWith("0").findOne(4000).parent().click();
    if (className("android.view.View").textStartsWith("签到成功").findOne(4000)) {
        className("android.view.View").textStartsWith("签到成功").findOne(4000).parent().child(className("android.view.View").textStartsWith("签到成功").findOne(4000).parent().childCount() - 1)
    }
    if (className("android.widget.Image").text("0x+wcp2R1bM4bU8gAAAABJRU5ErkJggg==").findOne(2000)) {
        className("android.widget.Image").text("0x+wcp2R1bM4bU8gAAAABJRU5ErkJggg==").findOne(2000).click()
    }
    
    if (className("android.widget.Image").text("treasure-box-enable-1.da338c08").findOne(2000)) {
        className("android.widget.Image").text("treasure-box-enable-1.da338c08").findOne(2000).parent().click()
        sleep(2000);
        if (className("android.view.View").text("javascript:;").findOne(4000)) {
            className("android.view.View").text("javascript:;").findOne(4000).click();
        }
    }
    if (className("android.view.View").text("逛商品赚金币").findOne(4000).parent().parent()) {
        className("android.view.View").text("逛商品赚金币").findOne(4000).parent().parent().click();
        if (className("android.view.View").textStartsWith("x").findOne(4000)) {
            for (i = 0; i < 4; i++) {
                sleep(7000);
                gesture(1000, [500, 1200], [500, 800]);
            }
            sleep(2000);
            back();
            sleep(2000);
        }
    }
    if (className("android.view.View").text("看小说赚金币").findOne(4000).parent().parent()) {
        className("android.view.View").text("看小说赚金币").findOne(4000).parent().parent().click();
        sleep(3000);
        threads.start(function() {
            if (id("novel_coin_exciting_ad_dismiss_btn").findOne()) {
                id("novel_coin_exciting_ad_dismiss_btn").findOne().click();
            }
        });
        for (i = 0; i < 5; i++) {
            click(device.width * 67 / 100, device.height * 85 / 100);
            sleep(500);
            click(device.width / 2, device.height * 90 / 100);
        }
        sleep(2000)
        for (i = 0; i < 200; i++) {
            gesture(1000, [device.width - 100, 800], [100, 800]);
            sleep(500);
        }
        back();
        sleep(1000);
        if (text("取消").findOne(1000)) {
            text("取消").findOne().click();
        }
        sleep(500);
        back();
        sleep(500);
    }
}
if (id("ahz").findOne(4000)) {
    id("ahz").findOne().parent().click();
    if (className("android.view.View").textStartsWith("签到成功").findOne(4000)) {
        className("android.view.View").textStartsWith("签到成功").findOne(4000).parent().child(className("android.view.View").textStartsWith("签到成功").findOne(4000).parent().childCount() - 1)
    }
    if (className("android.widget.Image").text("0x+wcp2R1bM4bU8gAAAABJRU5ErkJggg==").findOne(2000)) {
        className("android.widget.Image").text("0x+wcp2R1bM4bU8gAAAABJRU5ErkJggg==").findOne(2000).click()
    }
    if (className("android.widget.Image").text("开宝箱得金币").findOne(2000)) {
        try {
            className("android.widget.Image").text("开宝箱得金币").findOne(2000).parent().click();
        } catch (err) {
            toast("宝箱还未到领取时间!")
        }
        className("android.view.View").text("看完视频再领").findOne(4000).parent().click()
        className("android.widget.Image").text("9j1MaKG5QbLACL+oc7BNiiLbfh4FIyCYQIAoPdXAcqOUb0AAAAASUVORK5CYII=").findOne(4000).click()
        //className("android.widget.Image").text("图片").findOne(4000).parent().child(className("android.widget.Image").text("图片").findOne().parent().childCount() - 1).click();
    }
    if (className("android.widget.Image").text("treasure-box-enable-1.da338c08").findOne(2000)) {
        className("android.widget.Image").text("treasure-box-enable-1.da338c08").findOne(2000).parent().click()
        sleep(2000);
        if (className("android.view.View").text("javascript:;").findOne(4000)) {
            className("android.view.View").text("javascript:;").findOne(4000).click();
        }
    }
    if (className("android.view.View").text("逛商品赚金币").findOne(4000).parent().parent()) {
        className("android.view.View").text("逛商品赚金币").findOne(4000).parent().parent().click();
        if (className("android.view.View").textStartsWith("x").findOne(4000)) {
            for (i = 0; i < 4; i++) {
                sleep(7000);
                gesture(1000, [500, 1200], [500, 800]);
            }
            sleep(2000);
            back();
            sleep(2000);
        }
    }
    if (className("android.view.View").text("看小说赚金币").findOne(4000).parent().parent()) {
        className("android.view.View").text("看小说赚金币").findOne(4000).parent().parent().click();
        sleep(3000);
        threads.start(function() {
            if (id("novel_coin_exciting_ad_dismiss_btn").findOne()) {
                while (true) {
                    id("novel_coin_exciting_ad_dismiss_btn").findOne().click();
                }
            }
        });
        for (i = 0; i < 5; i++) {
            click(device.width * 67 / 100, device.height * 85 / 100);
            sleep(500);
            click(device.width / 2, device.height * 90 / 100);
        }
        sleep(2000)
        for (i = 0; i < 600; i++) {
            gesture(1000, [device.width - 100, 800], [100, 800]);
            sleep(500);
        }
        back();
        sleep(1000);
        if (text("取消").findOne(1000)) {
            text("取消").findOne().click();
        }
        threads.shutDownAll();
        sleep(500);
        back();
        sleep(500);
    }
}
/*
if (text("视频").findOne(4000)) {
    text("视频").findOne(4000).parent().click()
    sleep(2000);
}
if (className("android.widget.ImageView").id("lj").find()[0]) {
    className("android.widget.ImageView").id("lj").find()[0].click();
}
sleep(15000);
if (className("android.widget.ImageView").id("lj").find()[1]) {
    className("android.widget.ImageView").id("lj").find()[1].click();
}
sleep(15000);
className("android.widget.TextView").text("推荐").findOne(4000).parent().click();
sleep(2000);*/